package com.swolin.designPatter;

interface Product {
    void doSomething();
}

class ProductA implements Product {
    public void doSomething() {
        System.out.println("ProductA does something.");
    }
}

class ProductB implements Product {
    public void doSomething() {
        System.out.println("ProductB does something.");
    }
}

class Factory {
    public static Product getProduct(String productType) {
        if(productType.equalsIgnoreCase("A")) {
            return new ProductA();
        } else if(productType.equalsIgnoreCase("B")) {
            return new ProductB();
        } else {
            throw new IllegalArgumentException("Invalid product type.");
        }
    }
}

public class FactoryPatternExample {
    public static void main(String[] args) {
        Product product1 = Factory.getProduct("A");
        product1.doSomething();

        Product product2 = Factory.getProduct("B");
        product2.doSomething();
    }
}